<html>
    <head>
        <style>
            table{
                width: 500px;
                height:500px;
                background-color: beige;
            }
            table td{
                background-color: aqua;
            }
        </style>
    </head>
    <body>
        <table border="1">
            <tr><td></td><td></td><td></td></tr>
            <tr><td></td><td></td><td></td></tr>
            <tr><td></td><td></td><td></td></tr>
        </table>
        <script>
            let tds = document.querySelectorAll('td');
            tds.forEach(item=>{
                item.onclick = function(){
                    this.style.background = '#222';
                }
            })
        </script>
    </body>
</html>